﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Input;

namespace Pavilion.Locks
{
    public struct KeyboardLock : ILock
    {
        public bool IsPressed { get; set; }
        public Keys Key { get; set; }
        public string GameItemName { get; set; }

        public ILock Clone()
        {
            return new KeyboardLock()
            {
                GameItemName = this.GameItemName,
                IsPressed = this.IsPressed,
                Key = this.Key,
            };
        }

        public void Deserialize(XElement lockElement, string resourceName)
        {
            IsPressed = bool.Parse(lockElement.Attribute("IsPressed").Value);
            Key = (Keys)Enum.Parse(typeof(Keys), lockElement.Attribute("Key").Value);
        }

        public XElement Serialize()
        {
            XElement lockElement = new XElement("Lock");

            lockElement.Add(new XAttribute("IsPressed", IsPressed));
            lockElement.Add(new XAttribute("Key", Key));

            return lockElement;
        }

        public LockMonitorBase CreateLockMonitor(GameItem gameItem)
        {
            return new Pavilion.Locks.Monitors.KeyboardLockMonitor(this);
        }

        public override string ToString()
        {
            return this.GetType().Name;
        }
    }
}
